Package vg.modules.minimap

Source Code of vg.modules.minimap.MiniMapPanel

package vg.modules.minimap;

import java.awt.GridLayout;
import java.util.Observable;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import vg.core.AUserInterfaceElement;
import vg.core.IGraphView;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventChangeView;

public class MiniMapPanel extends AUserInterfaceElement {
  // Swing components
  private final JPanel panel;
  private JComponent miniMapView = null;
  // Mutex
  private final Object theMutexObject = new Object();
  /**
   * Constructor
   */
  public MiniMapPanel() {
    super("Minimap", null);   
    this.panel = new JPanel(new GridLayout(1,1));
    this.panel.setSize(300, 300);
  }

  public JComponent getView() {
    return (this.panel);
  }

  public void update(Observable o, Object arg) {
    if (arg instanceof AUIEvent) {
      AUIEvent event = (AUIEvent) arg;
      switch (event.getType()) {
        case DEF_CHANGE_VIEW: {
          final UIEventChangeView bufEvent = (UIEventChangeView) event;

          if(SwingUtilities.isEventDispatchThread()) {
            synchronized (theMutexObject) {
              updateView(bufEvent.getView());
            }
          } else {
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                synchronized (theMutexObject) {
                  updateView(bufEvent.getView());
                }
              }
            });           
          }
          break;
        }
        case DEF_CHANGE_UI_STYLE: {
          if(SwingUtilities.isEventDispatchThread()) {
            synchronized (theMutexObject) {
              SwingUtilities.updateComponentTreeUI(panel);
            }           
          } else {
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                synchronized (theMutexObject) {
                  SwingUtilities.updateComponentTreeUI(panel);
                }
              }
            });                       
          }
          break;
        }
      }
    }
  }
  ///////////////////////////////////////////////////////////////////////////
  // PRIVATE METHODS
  ///////////////////////////////////////////////////////////////////////////
  private void updateView(IGraphView igv) {
    // delete old minimap
    if (miniMapView != null) {
      panel.remove(miniMapView);
    }
    // if new minimap != null -> setup it
    if (igv != null) {
      miniMapView = igv.getMiniMap();
      if (miniMapView != null) {
        panel.add(miniMapView);
      }
    }
    panel.updateUI();   
  }
}
TOP

Related Classes of vg.modules.minimap.MiniMapPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.